public class IsSubTree {//leecode 572

    public boolean isSubtree(TreeNode root, TreeNode subRoot) {//先序遍历判断是否有相同的子树
        if(root==null) return false;
        return  isSameTree(root,subRoot)||isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot);

    }

    public boolean isSameTree(TreeNode root,TreeNode subRoot){//判断是否为相同的树
        if(root==subRoot)return true;
        if(root==null&&subRoot!=null||root!=null&&subRoot==null){
            return false;
        }
        if(root.val!=subRoot.val){
            return false;
        }
        return isSameTree(root.left,subRoot.left)&&isSameTree(root.right,subRoot.right);
    }
}
